home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Programmation / jedit / jedit5.1.0install.exe / {app} / macros / Java / Preview_JavaDoc_Of_Current_Buffer.bsh < prev   
Text File  |  2013-07-28  |  32KB  |  825 lines

  1. /*
  2.  * Preview_JavaDoc_Of_Current_Buffer.bsh
  3.  * version 1.8
  4.  * A BeanShell macro script for the jEdit text editor
  5.  * :tabSize=2:indentSize=2:noTabs=true:
  6.  * :folding=explicit:collapseFolds=1:
  7.  *
  8.  *  $Header$
  9.  *  Copyright (C) 2001-2003 Tom Gutwin
  10.  *  tgutwin@webarts.bc.ca
  11.  *
  12.  *   - Macro to create and preview the JavaDocs for the current buffer
  13.  *   - It tries to figure everything out for you.
  14.  *   - Map this macro to it to a button on the button bar and away you go!
  15.  *
  16.  * ************************************************************************
  17.  * ** Requires the Console plugin and the InfoViewer plugin
  18.  * ** ALSO
  19.  * ** Requires Downloading of the different doclets if you are going to use
  20.  *    them and pdfReaderCommand if using the pdfDoclet.
  21.  * ***********************************************************************
  22.  * **  Features
  23.  * ***********************************************************************
  24.  *
  25.  *   - most of the settings to customize how this macro performs are set with
  26.  *     boolean flags (see code below).  The following features are some of the
  27.  *     features already selectable/customizable
  28.  *
  29.  *   - javadoc of current buffer OR current buffer's package
  30.  *       set the 'doFullPackage'  boolean flag in the macro code
  31.  *       You can then save a copy of this macro as a different name
  32.  *       for example...  Preview_JavaDoc_Of_Current_Buffers_Package.bsh
  33.  *
  34.  *   - default Doclet is the standard Java Doclet
  35.  *     (the user can change the default doclet to use by changing the XXXX
  36.  *      variable in this macro)
  37.  *
  38.  *   - When this macro starts, a doclet choice dialog is presented.
  39.  *     this dialog can be bypassed by setting 'showDocletDialog' to false
  40.  *     see the code below
  41.  *
  42.  *   - Many of the standard Doclet commandline parms are preset with some
  43.  *     defaults...     header, footer etc.
  44.  *     They are all controlled via boolean flags in the code
  45.  *     Switch them on/off as you like.
  46.  *
  47.  *   - Includes the ability to use 'user selectable' doclets
  48.  *     The following are already built in. (you just have to go get the doclet)
  49.  *      > the DocBook doclet - dbdoclet  http://www.michael-a-fuchs.de
  50.  *      > the Bouvard Doclet - http://web.tiscali.it/no-redirect-tiscali/farello/bp/intro.html
  51.  *      > the XMLDoclet - http://
  52.  *      > the pdfdoclet (Java API to PDF) - http://sourceforge.net/projects/pdfdoclet
  53.  *      > others
  54.  *
  55.  *   - easy selection of output dir (defaults to system temp dir)
  56.  *     set with the 'outputDir' var in the macro code
  57.  *
  58.  *   - other standard doclets parameters have been supervised by variables.
  59.  *     see below for adding extra classpath, source path, title, header, footer
  60.  *     MORE below
  61.  *
  62.  * ************************************************************************
  63.  * This program is free software; you can redistribute it and/or
  64.  * modify it under the terms of the GNU General Public License
  65.  * as published by the Free Software Foundation; either version 2
  66.  * of the License, or any later version.
  67.  *
  68.  * This program is distributed in the hope that it will be useful,
  69.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  70.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  71.  * GNU General Public License for more details.
  72.  *
  73.  * You should have received a copy of the GNU General Public License
  74.  * along with the jEdit program; if not, write to the Free Software
  75.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  76. USA.
  77.  */
  78.  
  79. //{{{ _getClassName() method
  80. String _getClassName()
  81. {
  82.   /*
  83.    * Get_Class_Name.bsh - a BeanShell macro script for the
  84.    * jEdit text editor -  gets class name from buffer name
  85.    * Copyright (C) 2001 John Gellene
  86.    * jgellene@nyc.rr.com
  87.    *
  88.    * This program is free software; you can redistribute it and/or
  89.    * modify it under the terms of the GNU General Public License
  90.    * as published by the Free Software Foundation; either version 2
  91.    * of the License, or any later version.
  92.    *
  93.    * This program is distributed in the hope that it will be useful,
  94.    * but WITHOUT ANY WARRANTY; without even the implied warranty of
  95.    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  96.    * GNU General Public License for more details.
  97.    *
  98.    * You should have received a copy of the GNU General Public License
  99.    * along with the jEdit program; if not, write to the Free Software
  100.    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  101.    *
  102.    * $Id: Preview_JavaDoc_Of_Current_Buffer.bsh 10711 2007-09-22 09:12:15Z kpouer $
  103.    */
  104.   name = buffer.getName();
  105.   index = name.lastIndexOf('.');
  106.   return (index != -1 ? name.substring(0, index) : name);
  107. } //}}}
  108.  
  109. //{{{ _determinePackageName() method
  110. /** Trys to obtain the package name from the file **/
  111. String _determinePackageName()
  112. {
  113.   packageName = "";
  114.   text = buffer.getText(0, buffer.getLength());
  115.   //String lineSep = System.getProperty("line.separator");
  116.   /* look for the word package.
  117.     It must be at the start of a line.
  118.     It should not be within comments. (how can we easily determine this???)
  119.   */
  120.   packageWord = text.indexOf("package");
  121.   // If it is not on the first line of the file
  122.   // then look for the 1st occurence of "package" on its own line
  123.   if (packageWord > 0)
  124.     packageWord = text.indexOf("\npackage");
  125.  
  126.   if (packageWord != -1)
  127.   {
  128.     packageEOLine = text.indexOf(";", packageWord);
  129.     if (packageEOLine!= -1)
  130.       packageName = text.substring(packageWord+8,packageEOLine);
  131.   }
  132.   return packageName;
  133. } //}}}
  134.  
  135. //{{{ _chooseADir() method
  136. /** Chooses a directory and returns the path. **/
  137. /* Use this method if you want to customize the macro to choose
  138.    output and input directorys for things */
  139. String _chooseADir(String dialogTitle, String startDir)
  140. {
  141.   String retVal = "";
  142.   JFileChooser chooser = new JFileChooser(startDir);
  143.   chooser.setDialogTitle(dialogTitle);
  144.   chooser.setMultiSelectionEnabled(false);
  145.   chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  146.   if(chooser.showDialog(view, "Okay") == JFileChooser.APPROVE_OPTION)
  147.   {
  148.     retVal = chooser.getSelectedFile().getAbsolutePath();
  149.   }
  150.   return retVal;
  151. } //}}}
  152.  
  153. //{{{ _infoView() method
  154. void _infoView(View view, String urlStr)
  155. {
  156.   // first, check if the plugin is installed.
  157.   boolean version1 = false;
  158.   //With version 1.0 of the plugin ... the name changed to
  159.   //infoviewer.InfoViewerPlugin
  160.   if(jEdit.getPlugin("InfoViewerPlugin") == null)
  161.   {
  162.     if(jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null)
  163.     {
  164.       Macros.error(view,"You must install the InfoViewerPlugin"
  165.               + " to use this macro.");
  166.       return;
  167.     }
  168.     version1 = true;
  169.   }
  170.   try
  171.   {
  172.     // API change with version 1.0 of the InfoViewer
  173.     if (version1)
  174.       jEdit.getPlugin("infoviewer.InfoViewerPlugin").
  175.         openURL(view, urlStr);// version 1.0
  176.     else
  177.       jEdit.getPlugin("InfoViewerPlugin").
  178.         sendURL(new URL(urlStr), view); // pre 1.0
  179.   }
  180.   catch (MalformedURLException mu)
  181.   {
  182.       Macros.error(view,"Cannot find the url " + urlStr);
  183.   }
  184. } //}}}
  185.  
  186. //{{{ _returnSystemCommand() method
  187. String _returnSystemCommand(View view, String command)
  188. {
  189.   //{{{ first, check if the plugin is installed.
  190.   if(jEdit.getPlugin("console.ConsolePlugin") == null)
  191.   {
  192.           Macros.error(view,"You must install the Console plugin"
  193.                   + " to use this macro.");
  194.           return;
  195.   } //}}}
  196.  
  197.   //Macros.message(view, "Getting window manager.");
  198.   manager = view.getDockableWindowManager();
  199.   _console = (console.Console) manager.getDockable("console");
  200.   if (_console == null)
  201.   {
  202.       manager.showDockableWindow("console");
  203.       _console = (console.Console) manager.getDockable("console");
  204.   }
  205.   outputPane = _console.getOutputPane();
  206.  
  207.   text = outputPane.getText();
  208.   textLength = text.length();
  209.   runInSystemShell(view, command);
  210.   waitForConsole(view);
  211.   text = outputPane.getText();
  212.   textLength = text.length();
  213.   text = outputPane.getText().substring(textLength);
  214.   return text;
  215. } //}}}
  216.  
  217. //{{{ _ensureFolderExists() method
  218. /**
  219.  * Ensures that a folder exists.
  220.  * <TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="2">
  221.  *  <TR><TD COLSPAN="2">
  222.  *   <H2>Ensures that a folder exists</H2>
  223.  *    </TD></TR>
  224.  *
  225.  *    <TR><TD COLSPAN="2"> <BR>
  226.  *    <B>Description:</B><BR>
  227.  *    use it like this:
  228.  *  <br>    _ensureFolderExists(new File(fileName).getParentFile());
  229.  *    </TD></TR>
  230.  *    </TABLE>
  231.  *
  232.  * @param folder  The File object to check.
  233.  **/
  234. void _ensureFolderExists(File folder)
  235. {
  236.   if ( folder != null  &&  ! folder.exists() )
  237.   {
  238.       _ensureFolderExists(folder.getParentFile());
  239.       folder.mkdir();
  240.   }
  241. } //}}}
  242.  
  243.  
  244. String versionStr = "1.8";
  245. String SYSTEM_FILE_SEPERATOR = File.separator;
  246. String SYSTEM_TEMP_DIR = System.getProperty("java.io.tmpdir");
  247. //SYSTEM_TEMP_DIR = "/tmp";
  248. String SYSTEM_PATH_SEPERATOR = System.getProperty("path.separator");
  249.  
  250. // first, check if the plugin is installed.
  251. if(jEdit.getPlugin("console.ConsolePlugin") == null ||
  252.    (jEdit.getPlugin("InfoViewerPlugin") == null) &&
  253.    (jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null))
  254. {
  255.   if(jEdit.getPlugin("console.ConsolePlugin") == null)
  256.     Macros.error(view,"You must install the Console plugin"
  257.             + " to use this macro.");
  258.   else
  259.     Macros.error(view,"You must install the InfoViewerPlugin plugin"
  260.             + " to use this macro.");
  261. }
  262. else
  263. {
  264.  
  265.   String currBufferPath = buffer.getPath();
  266.  
  267.   //Macros.message(view,"Current Buffer Path:\n"+currBufferPath);
  268.   if (currBufferPath.endsWith(".java"))
  269.   {
  270.     /* Store Some class/package/path info for use later */
  271.     // Get the Package name
  272.     String packName = _determinePackageName();
  273.  
  274.     // Get the Class Name
  275.     String className = _getClassName();
  276.  
  277.     /* ********************************************************************** */
  278.     /* Change the Following Vars to personalize things */
  279.     /* You should also Change the Header and Botton javadoc text down below */
  280.     /* ********************************************************************** */
  281.     // header message
  282.     String yourProductUrlStr = "http://www.yourProductURL.goes.here";
  283.     String yourProductNameStr = "My Java Product Name";
  284.  
  285.     // header message
  286.     String yourBottomStr = "Released under a GNU Public License.";
  287.  
  288.     // PDFDoclet outputfilename
  289.     String pdfDocletOutputFilename = "PDFDoclet.Output.pdf";
  290.  
  291.     // PDFDoclet outputfilename
  292.     String pdfReaderCommand = "acro";
  293.  
  294.     // Output directory .... set this to somewhere permanent if you want
  295.     String outputDir = SYSTEM_TEMP_DIR;
  296.  
  297.     // Allow choice of the output dir at runtime
  298.     boolean chooseOutputDir = false;
  299.  
  300.     // This macro attempts to get the source search path right
  301.     // if its not getting it... this var gets added to the Javadoc search path
  302.     String extraSourceDir = "";
  303.  
  304.     // This macro doesn't do much with the javadoc classpath
  305.     // if its not getting it... this var gets added to the Javadoc classpath
  306.     String extraClassesDir = "";
  307.  
  308.     // flag to do the Javadoc on the package instead of just the file
  309.     // Set this to true then save this macro with a new name
  310.     // ie... Preview_Javadoc_Of_Current_Package.bsh
  311.     boolean doFullPackage = false;
  312.  
  313.     // set to false to default to the standard java doclet
  314.     boolean showDocletDialog = true;
  315.  
  316.     /* Set some default options for the javadoc command */
  317.     /* change these to suit how you like your output to show up */
  318.     /* better yet... make a little dialog for input at runtime */
  319.     int showOnlyLevel = 3; // protected is the default
  320.     String[] showOnlyStr = {"-public ","-protected ","-package ","-private"};
  321.  
  322.     /* some (not All) standard doclet options */
  323.     /* ************************************** */
  324.     // if you want one of the following options...
  325.     // set the corresponding flag to true
  326.     boolean[] optionFlags = {false,false,false,false,false,
  327.                              false,false,false,false};
  328.     String[] optionStrs = {"-use ","-version ","-author ","-nosince","-notree ",
  329.                            "-noindex ","-nohelp ","-nodeprecated ","-verbose"};
  330.  
  331.     // beware OS/2 users...
  332.     // ALL the following options break the IBM 1.3.0 JDK Javadoc tool
  333.     // don't ask me?
  334.     boolean addWindowTitle = true;
  335.     StringBuffer windowTitle = new StringBuffer("-windowtitle \"Javadoc for");
  336.     windowTitle.append((doFullPackage?"package ":"class "));
  337.     windowTitle.append(className);
  338.     windowTitle.append("\" ");
  339.  
  340.     /* DocTitle Text */
  341.     boolean addDocTitle = true;
  342.     StringBuffer docTitle = new StringBuffer("-doctitle \"");
  343.     docTitle.append("Your Document Title here Javadoc API");
  344.     docTitle.append("\" ");
  345.  
  346.     /* Header Text */
  347.     boolean addHeader = true;
  348.     StringBuffer header = new StringBuffer("-header \"");
  349.     header.append("<B><A href=\"");
  350.     header.append(yourProductUrlStr);
  351.     header.append("\">");
  352.     header.append(yourProductNameStr);
  353.     header.append("</A></B>");
  354.     header.append("<BR>Version xx.xx.xx");
  355.     // Format the current time.
  356.      java.text.SimpleDateFormat formatter
  357.          = new java.text.SimpleDateFormat ("yyyy.MMMMM.dd 'at' hh:mm:sszzz");
  358.      java.util.Date currentTime_1 = new java.util.Date();
  359.      String dateString = formatter.format(currentTime_1);
  360.     header.append("<BR><font size=-1>");
  361.     header.append(dateString);
  362.     header.append("</font>\" ");
  363.  
  364.     /* Footer Text */
  365.     boolean addFooter = true;
  366.     StringBuffer footer = new StringBuffer("-footer \"");
  367.     footer.append("Produced Using the <A href=\"http://www.jedit.org\">");
  368.     footer.append("jEdit</A><BR>Preview Javadoc Beanshell Macro.<BR>");
  369.     footer.append("Copyright © 2001-2003, ");
  370.     footer.append("<A href=\"http://www.webarts.bc.ca>\"");
  371.     footer.append("Tom B. Gutwin</A>");
  372.     footer.append("\" ");
  373.  
  374.     /* Bottom Text */
  375.     boolean addBottom = true;
  376.     StringBuffer bottom = new StringBuffer("-bottom \"");
  377.     bottom.append(yourBottomStr);
  378.     bottom.append("\" ");
  379.  
  380.     /*********************************************************************** */
  381.     /* All users setting now complete */
  382.     /*********************************************************************** */
  383.  
  384.  
  385.     // Store the directory where the buffer file lives
  386.     String savedBufferdir = currBufferPath.substring(0,
  387.       currBufferPath.length()-6-className.length());
  388.  
  389.     // build the full package.classname
  390.     StringBuffer fullClassName = new StringBuffer();
  391.     if (packName != null && !packName.equals(""))
  392.     {
  393.       fullClassName.append(packName);
  394.       fullClassName.append(".");
  395.     }
  396.     fullClassName.append(className);
  397.  
  398.     /* Javadoc needs the file to live in a directory structure */
  399.     /* named like its Package name */
  400.     // If needed... copy the file to the temp dir into its package dir */
  401.     String currBufferdir = savedBufferdir;
  402.     StringBuffer tmpBufferName = new StringBuffer(SYSTEM_TEMP_DIR);
  403.     if (packName != null && !packName.equals("") &&
  404.         savedBufferdir.indexOf(
  405.           packName.replace('.',File.separatorChar).trim()) == -1 )
  406.     {
  407.       // The buffer file is not in an appropriate named dir
  408.       // copy and work on it in temp
  409.       if (!SYSTEM_TEMP_DIR.endsWith(SYSTEM_FILE_SEPERATOR))
  410.         tmpBufferName.append(SYSTEM_FILE_SEPERATOR);
  411.       _ensureFolderExists(new File(tmpBufferName.toString() +
  412.         packName.replace('.', File.separatorChar).trim()));
  413.       tmpBufferName.append(fullClassName.toString().
  414.         replace('.', File.separatorChar).trim());
  415.       tmpBufferName.append(".java");
  416.       //Macros.message(view, "Saving "+tmpBufferName.toString());
  417.       buffer.save(view, tmpBufferName.toString(), false);
  418.  
  419.       // the rest of the macro uses the currBufferdir variable
  420.       currBufferPath = tmpBufferName.toString();
  421.       currBufferdir = currBufferPath.substring(0,
  422.         currBufferPath.length()-6-className.length());
  423.     }
  424.  
  425.     // some debug statements
  426.     //Macros.message(view,"Package Name ="+packName);
  427.     //Macros.message(view,"fullClassName ="+fullClassName);
  428.     //Macros.message(view,"Buffer Path ="+currBufferPath);
  429.     //Macros.message(view,"Buffer Dir ="+currBufferdir);
  430.  
  431.  
  432.     /* ************************************************* */
  433.     /* ***********  On with the Processing ************* */
  434.     Object[] options = { "Standard Java Doclet", "Bouvard Doclet",
  435.                          "DocBook Doclet", "XML Doclet", "PDF Doclet" };
  436.     String[] docletClassName = { "", "bp.doclet.Bouvard",
  437.                                  "com.mf.doclet.docbook.DocBookDoclet",
  438.                                  "codeinsight.xmldoclet.XMLDoclet",
  439.                                  "com.tarsec.javadoc.pdfdoclet.PDFDoclet"};
  440.     String[] docletClassPath = { "", "Bouvard.jar", "dbdoclet.jar",
  441.                                  "xmldoclet.jar",
  442.                                  "pdfdoclet.jar:itext.jar:/usr/lib/pkgs" };
  443.     String PDFDocletConfigPropertiesFile = "pdfdoclet.config.properties";
  444.     // Set the DEFAULT Doclet to the JavaDoclet
  445.     String proceed = options[0];
  446.  
  447.     /* Shows a Doclet Selection Dialog */
  448.     if (showDocletDialog)
  449.       proceed = JOptionPane.showInputDialog(view,
  450.                             "Choose the Doclet to use for previewing the"+
  451.                             "\n" + className + " JavaDocs."+
  452.                             "\n(Bypass this dialog... set "+
  453.                             "'showDocletDialog=false;' in the macro)",
  454.                             "JavaDoc Buffer Macro - version "+versionStr,
  455.                             JOptionPane.QUESTION_MESSAGE, null, options,
  456.                             options[0]);
  457.  
  458.     if (proceed != null)
  459.     {
  460.       // this is where you could use the  _chooseADir(String startDir) method
  461.       // to choose an output dir at runtime.
  462.       if (chooseOutputDir)
  463.         outputDir = _chooseADir("Please Choose an Output Directory.",outputDir);
  464.  
  465.       docletChoice = 0;
  466.       for (int choiceNum = 0; choiceNum < options.length;choiceNum++)
  467.       {
  468.         if (((String)proceed).equals((String)options[choiceNum]))
  469.         {
  470.           docletChoice = choiceNum;
  471.           choiceNum = options.length;
  472.         }
  473.       }
  474.  
  475.       // The currBufferSrcDir expects the current buffer to be in a subDirectory
  476.       // path the same as the package name
  477.       // THIS is definitely NOT always the case
  478.       String currBufferSrcDir = currBufferPath.substring(0,
  479.         currBufferPath.length()-fullClassName.toString().length()-5);
  480.  
  481.       if(outputDir != null && !outputDir.equals(""))
  482.       {
  483.         // you might need some of the follwing if you want to add some
  484.         // commandline parms
  485.         String jedit_userdir=System.getProperty("user.home") +
  486.           SYSTEM_FILE_SEPERATOR +".jedit";
  487.         String jedit_homedir=jEdit.getJEditHome();
  488.         String currClassPath=System.getProperty("java.class.path");
  489.         String java_home=System.getProperty("java.home");
  490.  
  491.         // Construct the command which will be executed
  492.         StringBuilder command = new StringBuilder(java_home);
  493.         if (java_home.toLowerCase().endsWith("jre"))
  494.           command.append(File.separator).append("..");
  495.         command.append(File.separator).append("bin");
  496.         command.append(File.separator).append("javadoc ");
  497.  
  498.         if (!((String)proceed).equals((String)options[0]))
  499.         {
  500.           //{{{ general parms for 'other' doclets
  501.           command.append("-doclet \"");
  502.           command.append(docletClassName[docletChoice]);
  503.           command.append("\" ");
  504.           command.append("-docletpath \"");
  505.           command.append(jedit_userdir);
  506.           command.append(SYSTEM_FILE_SEPERATOR);
  507.           command.append("jars");
  508.           command.append(SYSTEM_FILE_SEPERATOR);
  509.           command.append(docletClassPath[docletChoice]);
  510.           command.append("\" ");
  511.           //}}}
  512.  
  513.           //{{{ Bouvard Doclet
  514.           // This assumes the Bouvard.jar already exists
  515.           // in the jeditUser/jars dir
  516.           if (((String)proceed).equals((String)options[1]))
  517.           {
  518.             /* Specify the output dir */
  519.             command.append("-d \"");
  520.             command.append(outputDir);
  521.             command.append("\" ");
  522.           } //}}}
  523.  
  524.           //{{{ the DocBookDoclet has an extra parm
  525.           if (((String)proceed).equals((String)options[2]))
  526.           {
  527.             command.append("-properties \"");
  528.             command.append(jedit_userdir);
  529.             command.append(SYSTEM_FILE_SEPERATOR);
  530.             command.append("macros");
  531.             command.append(SYSTEM_FILE_SEPERATOR);
  532.             command.append("Java");
  533.             command.append(SYSTEM_FILE_SEPERATOR);
  534.             command.append("dbdoclet-xml.properties\" ");
  535.           } //}}}
  536.  
  537.           //{{{ the XMLDoclet has an extra parm
  538.           if (((String)proceed).equals((String)options[3]))
  539.           {
  540.             /* Specify the output dir */
  541.             //command.append("-d \"");
  542.             //command.append(outputDir);
  543.             //command.append("\" ");
  544.           } //}}}
  545.  
  546.           //{{{ the PDFDoclet has an extra parm
  547.           if (((String)proceed).equals((String)options[4]))
  548.           {
  549.             command.append("-pdf \"");
  550.             command.append(outputDir);
  551.             command.append(SYSTEM_FILE_SEPERATOR);
  552.             command.append(pdfDocletOutputFilename);
  553.             command.append("\" ");
  554.             if (PDFDocletConfigPropertiesFile != null
  555.               &&!PDFDocletConfigPropertiesFile.equals(""))
  556.             {
  557.               command.append(" -workdir \"");
  558.               command.append(outputDir);
  559.               command.append("\" ");
  560.               command.append("-config \"");
  561.               command.append(jedit_userdir);
  562.               command.append(SYSTEM_FILE_SEPERATOR);
  563.               command.append("macros");
  564.               command.append(SYSTEM_FILE_SEPERATOR);
  565.               command.append("Java");
  566.               command.append(SYSTEM_FILE_SEPERATOR);
  567.               command.append(PDFDocletConfigPropertiesFile);
  568.               command.append("\"");
  569.             }
  570.           } //}}}
  571.  
  572.         }
  573.         else
  574.         { 
  575.           //{{{ standard doclet parms
  576.           if (addWindowTitle)
  577.             command.append(windowTitle.toString());
  578.           if (addDocTitle)
  579.             command.append(docTitle.toString());
  580.           if (addHeader)
  581.             command.append(header.toString());
  582.           if (addFooter)
  583.             command.append(footer.toString());
  584.           if (addBottom)
  585.             command.append(bottom.toString());
  586.  
  587.           /* add the on/off options */
  588.           for (int opt = 0; opt <optionFlags.length; opt++)
  589.           {
  590.             if (optionFlags[opt])
  591.               command.append(optionStrs[opt]);
  592.           }
  593.  
  594.           /* Specify the output dir */
  595.           command.append("-d \"");
  596.           command.append(outputDir);
  597.           command.append("\" ");
  598.           
  599.           //}}}
  600.  
  601.         }
  602.  
  603.         /* Set the Level of detail to show */
  604.         command.append(" ");
  605.         command.append(showOnlyStr[showOnlyLevel]);
  606.  
  607.         //{{{ if not found add your source dir to the 'extraClassesdir' var
  608.         command.append(" -classpath \"");
  609.         command.append(SYSTEM_TEMP_DIR);
  610.         command.append(SYSTEM_PATH_SEPERATOR);
  611.         command.append(System.getProperty("java.class.path"));
  612.         command.append(SYSTEM_PATH_SEPERATOR);
  613.         command.append(extraClassesDir);
  614.         command.append("\" ");
  615.         //}}}
  616.  
  617.         /* **** Done with the options ***** */
  618.         /* Specify the package or file name */
  619.         if (doFullPackage && packName != null && !packName.equals(""))
  620.         {
  621.           /* Guess where the package source is located */
  622.           /* if not found... add your source dir to the 'extraSourcedir' var */
  623.           command.append("-sourcepath \"");
  624.           command.append(savedBufferdir);
  625.           command.append(SYSTEM_PATH_SEPERATOR);
  626.           command.append(currBufferSrcDir);
  627.           command.append(SYSTEM_PATH_SEPERATOR);
  628.           command.append(currBufferSrcDir);
  629.           command.append(SYSTEM_FILE_SEPERATOR);
  630.           command.append("..");
  631.           command.append(SYSTEM_PATH_SEPERATOR);
  632.           command.append(currBufferSrcDir);
  633.           command.append(SYSTEM_FILE_SEPERATOR);
  634.           command.append("..");
  635.           command.append(SYSTEM_FILE_SEPERATOR);
  636.           command.append("..");
  637.           command.append(SYSTEM_PATH_SEPERATOR);
  638.           command.append(currBufferSrcDir);
  639.           command.append(SYSTEM_FILE_SEPERATOR);
  640.           command.append("..");
  641.           command.append(SYSTEM_FILE_SEPERATOR);
  642.           command.append("..");
  643.           command.append(SYSTEM_FILE_SEPERATOR);
  644.           command.append("..");
  645.           command.append(SYSTEM_PATH_SEPERATOR);
  646.           command.append(currBufferSrcDir);
  647.           command.append(SYSTEM_FILE_SEPERATOR);
  648.           command.append("..");
  649.           command.append(SYSTEM_FILE_SEPERATOR);
  650.           command.append("..");
  651.           command.append(SYSTEM_FILE_SEPERATOR);
  652.           command.append("..");
  653.           command.append(SYSTEM_FILE_SEPERATOR);
  654.           command.append("..");
  655.           command.append(SYSTEM_PATH_SEPERATOR);
  656.           command.append(currBufferdir);
  657.           command.append(SYSTEM_PATH_SEPERATOR);
  658.           command.append(extraSourceDir);
  659.           command.append("\" ");
  660.  
  661.           command.append(packName);
  662.         }
  663.         else
  664.         {
  665.           //{{{ add the base sourcepath
  666.           command.append("-sourcepath \"");
  667.           command.append(savedBufferdir);
  668.           command.append(SYSTEM_PATH_SEPERATOR);
  669.           command.append(currBufferSrcDir);
  670.           command.append(SYSTEM_PATH_SEPERATOR);
  671.           command.append(currBufferdir);
  672.           command.append(SYSTEM_PATH_SEPERATOR);
  673.           command.append(extraSourceDir);
  674.           command.append("\" ");
  675.           //}}}
  676.  
  677.           //{{{ now add the file to javadoc
  678.           command.append("\"");
  679.           command.append(currBufferPath);
  680.           command.append("\"");
  681.           //}}}
  682.  
  683.         }
  684. System.out.println("****************************************************************");
  685. System.out.println(command.toString());
  686. System.out.println("****************************************************************");
  687.         retVal = _returnSystemCommand(view, command.toString());
  688.         if (retVal.indexOf("error") == -1)
  689.         {
  690.             
  691.           // Build the url for the Viewer
  692.           // If you don't want to use the InfoViewer plugin...
  693.           // easy, change the implementation in this macros _infoView method
  694.           StringBuffer urlStr = new StringBuffer();
  695.           urlStr.append("file:///");
  696.           urlStr.append(outputDir.replace('\\', '/').trim());
  697.           if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  698.             urlStr.append("/");
  699.           if (doFullPackage)
  700.           {
  701.             urlStr.append("index.html");
  702.           }
  703.           else
  704.           {
  705.             if (packName != null && !packName.equals(""))
  706.             {
  707.               urlStr.append(packName.replace('.', '/').trim());
  708.               urlStr.append("/");
  709.             }
  710.             //Macros.message(view, packName);
  711.             urlStr.append(className);
  712.             urlStr.append(".html");
  713.             //Macros.message(view, urlStr.toString());
  714.           }
  715.  
  716.           // now which viewer (standard or Pecuchet)
  717.           if (!showDocletDialog || ((String)proceed).equals((String)options[0]))
  718.             _infoView(view, urlStr.toString());
  719.  
  720.           else if (((String)proceed).equals((String)options[1]))
  721.           {
  722.             // Bouvard Browser
  723.             // This assumes the Pecuchet.jar already exists
  724.             // and xerces is in the classpath already
  725.             StringBuffer classPath = new StringBuffer("\"");
  726.             classPath.append(jedit_userdir);
  727.             classPath.append(SYSTEM_FILE_SEPERATOR);
  728.             classPath.append("jars");
  729.             classPath.append(SYSTEM_FILE_SEPERATOR);
  730.             classPath.append("Pecuchet.jar");
  731.             classPath.append(SYSTEM_PATH_SEPERATOR);
  732.             classPath.append(jedit_homedir);
  733.             classPath.append(SYSTEM_FILE_SEPERATOR);
  734.             classPath.append("jars");
  735.             classPath.append(SYSTEM_FILE_SEPERATOR);
  736.             classPath.append("Pecuchet.jar");
  737.             classPath.append(SYSTEM_PATH_SEPERATOR);
  738.             classPath.append(currClassPath);
  739.             classPath.append("\"");
  740.  
  741.             StringBuffer bViewerCommand = new StringBuffer("java -classpath ");
  742.             bViewerCommand.append(classPath);
  743.             bViewerCommand.append(" ");
  744.             bViewerCommand.append("-Dorg.xml.sax.driver=");
  745.             bViewerCommand.append("org.apache.xerces.parsers.SAXParser");
  746.             bViewerCommand.append(" ");
  747.             bViewerCommand.append("bp.app.Main ");
  748.             bViewerCommand.append(outputDir);
  749.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  750.               bViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  751.             bViewerCommand.append("data.bou &");
  752.             retVal = _returnSystemCommand(view, bViewerCommand.toString());
  753.             StringBuffer macroMessage =
  754.               new StringBuffer("When the Pecuchet browser starts.\n");
  755.             macroMessage.append("Open file: ");
  756.             macroMessage.append(outputDir);
  757.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  758.               macroMessage.append(SYSTEM_FILE_SEPERATOR);
  759.             macroMessage.append("data.bou");
  760.             //Macros.message(view, macroMessage.toString());
  761.           }
  762.           else if (((String)proceed).equals((String)options[2]))
  763.           {
  764.             // XML Doclet
  765.             // Use a new jEdit Buffer
  766.             StringBuffer newFile = new StringBuffer(outputDir);
  767.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  768.               newFile.append(SYSTEM_FILE_SEPERATOR);
  769.             newFile.append("Reference.xml");
  770.             Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  771.           }
  772.           else if (((String)proceed).equals((String)options[3]))
  773.           {
  774.             // XML Doclet
  775.             // Use a new jEdit Buffer
  776.             StringBuffer newFile = new StringBuffer(outputDir);
  777.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  778.               newFile.append(SYSTEM_FILE_SEPERATOR);
  779.             newFile.append("output.xml");
  780.             Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  781.           }
  782.           else if (((String)proceed).equals((String)options[4]))
  783.           {
  784.             // pdf Doclet
  785.             StringBuffer pdfViewerCommand = new StringBuffer(pdfReaderCommand);
  786.             pdfViewerCommand.append(" ");
  787.             pdfViewerCommand.append(outputDir);
  788.             pdfViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  789.             pdfViewerCommand.append(pdfDocletOutputFilename);
  790.             retVal = _returnSystemCommand(view, pdfViewerCommand.toString());
  791.           }
  792.           else
  793.           {
  794.             // put the viewers for other doclets here
  795.           }
  796.         }
  797.         else
  798.           Macros.error(view, "Javadoc did NOT complete successfully. " +
  799.             "See the console output");
  800.       }
  801.     }
  802.   }
  803.   else
  804.     Macros.error(view, "Current Buffer does NOT appear to be a Java File");
  805. }
  806.  
  807. /*
  808.  
  809. Macro index data (in DocBook format)
  810.  
  811.   <listitem>
  812.     <para><filename>Preview_Javadoc_of_Buffer.bsh</filename></para>
  813.     <abstract><para>
  814.       Create and display API documentation for the current buffer.
  815.     </para></abstract>
  816.   <para>
  817.     The macro includes various configuration variables you can change; see the comment at the beginning of the macro source for details.
  818.   </para>
  819.   </listitem>
  820.  
  821. */
  822.  
  823. // end Preview_JavaDoc_of_Buffer.bsh
  824.  
  825.